package com.erhirent.view;

import java.util.List;

import com.erhairent.tools.InputTools;
import com.erhirent.bean.Brand;
import com.erhirent.bean.Type;

public class AddView extends View {

	int type;
	int brand;
	String name;
	String car_number;
	String remark;
	String color;
	double value;
	double payday;
	int isrent;
	int isputaway;
	String rent;
	String putaway;

	@Override
	public View showView() {
		System.out.println("汽车类型如下:");
		List<Type> list1 = mcar.querytype();
		if (list1.size() != 0) {
			System.out.println("---------------------------");
			System.err.println("类型ID\t" + "类型名称\t");
			for (Type type : list1) {
				System.out.print(type.gettypeId() + "\t");
				System.out.println(type.gettypeName() + "\t");
			}
			System.out.println("---------------------------");
		} else {
			System.out.println("获取类型失败");
			return mView;
		}

		System.out.println("请选择需要添加汽车的类型编号:");
		//判断在可选范围内
		type = InputTools.nextInt();

		System.out.println("汽车品牌如下:");
		List<Brand> list2 = mcar.querybrand();
		if (list2.size() != 0) {
			System.out.println("---------------------------");
			System.err.println("品牌ID\t" + "品牌名称\t");
			for (Brand brand : list2) {
				System.out.print(brand.getBrandId() + "\t");
				System.out.println(brand.getBrandName() + "\t");
			}
			System.out.println("---------------------------");
		} else {
			System.out.println("获取品牌失败");
			return mView;
		}

		//
		System.out.println("----------------");
		System.out.println("请选择需要添加汽车的品牌编号:");
		brand = InputTools.nextInt();

		System.out.println("----------------");
		System.out.println("车型号:");
		name = InputTools.next();

		System.out.println("----------------");
		System.out.println("车牌号:");
		car_number = InputTools.next();

		System.out.println("----------------");
		System.out.println("概要:");
		remark = InputTools.next();
		System.out.println("----------------");
		System.out.println("颜色:");
		color = InputTools.next();

		System.out.println("----------------");
		System.out.println("汽车价格:");
		value = InputTools.nextDouble();

		System.out.println("----------------");
		System.out.println("每日租金:");
		payday = InputTools.nextDouble();

		System.out.println("----------------");
		System.out.println("是否可借(0:可借    1:不可借)");
		isrent = InputTools.nextInt();
		if (isrent == 0) {
			rent = "可借";
		} else {
			rent = "不可借";
		}
		System.out.println("----------------");
		System.out.println("是否上架(0:上架    1:不上架)");
		isputaway = InputTools.nextInt();

		if (isputaway == 0) {
			putaway = "上架";
		} else {
			putaway = "不上架";
		}

		if (mcar.addCar(name, remark, brand, type, payday, car_number, color, value)) {
			System.out.println("添加成功");
		} else {
			System.out.println("添加失败");
			return mView;
		}

		return mView;

	}

}
